package cn.com.cpic.insurance.rulecheck.core.test.expression;

import cn.com.cpic.insurance.rulecheck.core.javacc.RuleCheck;
import cn.com.cpic.insurance.rulecheck.core.test.BaseRuleCheckTestCase;

/**
 * 
 * 
 * @author 代波
 * @since 2011-8-20
 */
public abstract class BaseExpressionTestCase extends BaseRuleCheckTestCase {
	protected final Object operate(String exp) {
		try {
			return RuleCheck.parseLogicalExpression(exp).operate(ctx);
		} catch (Throwable e) {
			throw new IllegalArgumentException("表达式无法解析：" + exp, e);
		}
	}

	protected final void assertOperateException(String exp, Class<? extends Exception> expectedExceptionClass) {
		try {
			operate(exp);
			fail("Block did not throw an exception of type: " + expectedExceptionClass.getName());
		} catch (Exception e) {
			Throwable cause = e.getCause();
			assertTrue("Caught exception of type <" + cause.getClass().getName() + ">, expected one of type <"
					+ expectedExceptionClass.getName() + ">", expectedExceptionClass.isInstance(cause));
		}
	}
}
